/*================================================================
*   文件名称：main.cpp
*   创 建 者：yang qiang
*   创建日期：2021年02月28日
*   描    述：
*   Copyright (C) 2021 All rights reserved.
*
* ================================================================*/


#include <iostream>
#include <vector>

using namespace std;

int dfs(int i, int j,  vector<vector<int>>&maze, vector<vector<int>>&path){
    if(i >= maze.size() || j >= maze[0].size() || maze[i][j] == 1){
        return false;
    }

    path.push_back({i, j});
    if(i == maze.size() - 1 && j == maze[0].size()-1){
        return true;
    }

    if(dfs(i+1, j, maze, path) || dfs(i, j+1, maze, path)){
        return true;
    }else{
        path.pop_back();
    }

    return false;
}


int get_min_path(int m, int n, vector<vector<int>>&maze){
    vector<vector<int>> path;
    dfs(0, 0, maze, path);

    for(int i = 0; i < path.size(); i++){
        cout <<"("<< path[i][0] << "," << path[i][1] << ")" << endl;
    }

    return 0;
}

int main(){
    int m ,n;
    while(cin >> m >> n){
        vector<vector<int>> maze(m, vector<int>(n, 0));
        for(int i = 0; i < m; i++){
            for(int j = 0; j < n; j++){
                cin >> maze[i][j];
            }
        }

        get_min_path(m, n, maze);
    }

    return 0;
}
